<template>
    <el-header class="header">
      <Condition   @search="gosearch"></Condition>
    </el-header>
    <el-main>
         <!-- <ATTable></ATTable> -->
        <businessTable v-if="detailist.length>0" :propData="propData" :pageNum="from.pageNum" :logdingB="logding" :pageSize="pageSize" :tableData="detailist" @getdata="getlistdata"></businessTable>
            <el-empty v-else description="暂无数据" />
   </el-main>
</template>

<script>
import businessTable from '../components/businessTable.vue'
import Condition from '../components/condition.vue'
import ATTable from '../components/ATTable.vue'
export default {
    data(){
        return{
         tabsdata:true,
         from:{
           startTime:"",
           endTime:'',
           pageSize:10,
           pageNum:0,
        },
        logding:false,
        list:[],
        detailist:[],
        rules:{},
        propData:[]
        //  dataAPI:
        }
    },
    components:{
        Condition,
        businessTable,
        ATTable
    },
    created(){
      this.getlistdata()

//       cost
// : 
// 45
// frequency
// : 
// 36
// lastYearCost
// : 
// 45
// lastYearFrequency
// : 
// 23
    },
    methods:{
        refresh(){

        },
           search(){
      this.from = {...this.from}
      this.from.pageNum = 0
       this.detailist = []
       this.getlistdata()
      // this.$refs.pullresh.reset()
   },
    getlist(data){
      // this.list =  [...this.list,...data]
   }, 
    gosearch(data){
      this.from.startTime = data.startTime
      this.from.endTime = data.endTime
      this.search()
    },
      async getlistdata(){
             this.logding =true
             this.from.pageNum++
             this.from = {...this.from}
            let res  =  await this.$API.ActivityMonitoringM.activityDuplicate.activityTypeDimension.post(this.from)

       
            if(res.code=='0'){
               let nuedata = []
              if(res.data.length>0){
              this.propData = this.recombination(res.data)
                   nuedata = await this.recombinationdata(res.data)
              }
                 this.from.pageNum = res.pageNum
                this.logding = false
                this.detailist = [...this.detailist,...nuedata]
            }
        },
                recombination(list){
          let arr = []
          let obj = {
            prop:'data',
            label:'区域名称',
           arrs:[
             {
              prop:'activityType'
            },
            {
              prop:'name',
            },
          ],
          }
          arr.push(obj)
          list.forEach((item,index)=>{
                let obj1 = {
                prop:`address`+index,
                label:item.regionName,
                arrs:[]
                }
                arr.push(obj1)
          })
          console.log(arr)
          return  arr
        },
              async  recombinationdata(list){
          let asrr = []
          let number = 0
          list.forEach((item,index)=>{
             let asrrs = []
             number  = item.activities.length
            item.activities.forEach((item1,index1)=>{
            let arr = []
            for(let i= 0; i<4;i++){
              if(i==0){
               let obj = {
                  activityType:item1.activityType,
                 name:'活动次数（场）',
               }
               obj['address'+index] = item1.cost
               arr .push(obj)
            }
                if(i==1){
               let obj = {
                  activityType:item1.activityType,
                 name:'非线性费用投入（万）',
               }
               obj['address'+index] = item1.frequency
               arr .push(obj)
            }
                if(i==2){
               let obj = {
                  activityType:item1.activityType,
                 name:'去年活动次数（场）',
               }
               obj['address'+index] = item1.lastYearCost
               arr .push(obj)
            }
                if(i==3){
               let obj = {
                  activityType:item1.activityType,
                 name:'去年非线性费用投入（万）',
               }
               obj['address'+index] = item1.lastYearFrequency
               arr .push(obj)
            }
          }

          asrrs.push(arr)
            })
            asrr.push(asrrs)
          })
          console.log(asrr)
          let arrsssss = []
      
          asrr.forEach((item,index)=>{
                let arrssds = []
              asrr.forEach((item1,index1)=>{
                console.log(item1,asrr[index1+1])
                    console.log(item1,index)
                    arrssds = [...arrssds,...asrr[index1]]
                  console.log(arrssds)
              })
           
              arrsssss.push(arrssds)
          })
          // arrsssss[0].forEach((item,index)=>{
          //      item.forEach()
          // })
          console.log(arrsssss)
          let lissad = []
          for(let i =0;i<arrsssss[0].length;i++){
             let obj = []
            for(let k = 0;k<arrsssss[0].length;k++){
                if(arrsssss[0][i][0].activityType==arrsssss[0][k][0].activityType){
                           obj = [...obj,...arrsssss[0][k]]
                }
               }
            lissad.push(obj)
          }
          let asdsad = []
          lissad.forEach(item=>{
            let sdsa  =[]
              item.forEach(item1=>{
                let onbjs = {}
                item.forEach(item2=>{
                  if(item1.name == item2.name){
                      onbjs = {...onbjs,...item2}
                   }
                })
                sdsa.push(onbjs)
              })
              asdsad.push(sdsa)
          })
          console.log(asdsad)
        asdsad = asdsad.splice(0,number)
       
            let sadasadafas = []
          asdsad.forEach(item=>{
             let objs = []
              asdsad.forEach(item1=>{
                  objs = [...objs,...item1.splice(0,4) ] 
               })
               sadasadafas.push(objs)
          })
          console.log(sadasadafas)
          // sadasadafas[0]
          return sadasadafas[0]
        },
    }
}
</script>

<style scoped>
.el-main{
  padding: 5px !important;
}
.header{
    width: 100%;
    min-height:72px;
    display: flex;
}
.top{
    margin-top: 1.6rem;
}
.el-header{
--el-header-height:none;
}
</style>